import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import { fetchCartPostSlice } from './cart.actions';


const initialState = {
	balls: [],
	loading: false,
	errors: null
};

export const cartSlice = createSlice({
	name: 'cart',
	initialState,
	reducers: {
	},
	extraReducers: (builder) => {
		builder.addCase(fetchCartPostSlice.pending, (state) => {
			state.loading = true;
			state.errors = null;
		});
		builder.addCase(
			fetchCartPostSlice.fulfilled,
			(state, action) => {
				state.balls.push(action.payload);
				state.loading = false;
			}
		);
		builder.addCase(fetchCartPostSlice.rejected, (state, action) => {
			// state.loading = true;
			state.errors = action.error.message;
		});
	}
});

export default cartSlice.reducer;
// export const {addToFavorite} = ballsSlice.actions;
